<?php
include '../controllers/ADController.php';
include '../utils/htmlFilter.php';
date_default_timezone_set("PRC"); 
$advertisings = getAllAdvertising();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="../js/admanager.js"></script>
</head>
<body>
	<a href='../index.php'>返回首页</a><hr/>
	<table border='2' rules='rows' cellpadding='8%' align='center' width='80%'>
		<tr><th colspan="2"><h2>添加广告</h2></th></tr>
		<tr><th>标题</th><td><input id="title" type="text" size="100"></input></td></tr>
		<tr><th>简介</th><td><input id="summary" type="text" size="140"></input></td></tr>
		<tr><th>详情</th><td><textarea id="details" rows="6" cols="80"></textarea></td></tr>
		<tr><th>广告链接</th><td><input id="adUrl" type="text" size="140"></input></td></tr>
		<tr><th>广告分类</th><td><input id="category" type="text" size="20"></input></td></tr>
		<tr><th>是否开启</th><td><select id="status"><option value="0">关闭</option><option value="1">开启</option></select></td></tr>
		<tr align="center"><td colspan="2"><input type="button" value="添加广告" onclick="addAdvertising();"></input></td> </tr>
	</table>
	<br />
	<br />
	<div id="advertising_list">
	<table border='2' rules='rows' cellpadding='8%' align='center' width='80%'>
		<tr><th colspan="6"><h2>广告列表</h2></th></tr>
		<tr><th>广告ID</th><th>标题</th><th>简介</th><th>创建时间</th><th>状态</th><th>操作</th></tr>
		<?php
		$adCount = count($advertisings);
		for ($i = 0; $i < $adCount; $i++) {
			
			$advertising = $advertisings[$i];
			$adId = $advertising->getAdId();
			$title = $advertising->getTitle();
			$summary = $advertising->getSummary();
			$details = $advertising->getDetails();
			$adUrl = $advertising->getAdUrl();
			$createTime = $advertising->getCreateTime();
			$status = $advertising->getStatus();
			$category = $advertising->getCategory();
			$formatTime = date("y-m-d h:i:s",$createTime);
			echo "<tr align='center'><td>$adId</td><td>$title</td><td>$summary</td><td>$formatTime</td>";
			if ($status == 0) {
				echo "<td>关闭</td>";
			}	
			else 
			{
				echo "<td>开启</td>";
			}
			echo "<td><input type='button' value='修改' onclick='jumpToUpdate($adId,\"$title\",\"$summary\",\"$adUrl\",\"$category\",$status);'></input>";
			echo "<input type='button' value='删除' onclick='deleteAdvertising($adId);'></input><td>";
			echo "<textarea style='display:none' id='details_$adId'>$details</textarea>";
			echo "</tr>";
		}
		?>
	</table>
	</div>
</body>
</html>
